home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _8B364EFB8F2146A0BDB49B7B15E0312B < prev    next >
Encoding:
Text File  |  2004-01-06  |  3.2 KB  |  114 lines

  1. -- Idle Manager - 
  2. -- Created by Sten; 18092002
  3. -- improved and made customizeable by Petar may2003
  4. --------------------------
  5. -- this new and improved manager maintains a list of idle animations based on the model of the entity by discovering
  6. -- available animations and their durations 
  7.  
  8.  
  9.  
  10. IdleManager =     {
  11.  
  12.         ModelTable = {},
  13.         TagTable = {},
  14.         CountTable = {},
  15.     
  16.         AnimationTable =     {
  17.                 {Name = "_kickground01", duration = 4, Tag = 0},
  18.                 {Name = "_kickground02", duration = 4, Tag = 0},
  19.                 {Name = "_idle_leanright", duration = 4, Tag = 0},
  20.                 {Name = "_idle_leanleft", duration = 5, Tag = 0},
  21.                 {Name = "_itchbutt", duration = 2, Tag = 0},
  22. --                {Name = "_rubneck", duration = 3, Tag = 0},
  23.                 --{Name = "_sneeze", duration = 4, Tag = 0},
  24.                 
  25.                 {Name = "_checkwatch1", duration = 2, Tag = 0},
  26.                 {Name = "_checkwatch2", duration = 3, Tag = 0},
  27.                 {Name = "_chinrub", duration = 4, Tag = 0},
  28.                 {Name = "_foottap1", duration = 3, Tag = 0},
  29.                 {Name = "_foottap2", duration = 5, Tag = 0},
  30.                 {Name = "_headscratch1", duration = 2, Tag = 0},
  31.                 {Name = "_headscratch2", duration = 3, Tag = 0},
  32.                 {Name = "_humming", duration = 5, Tag = 0},
  33.                 {Name = "_insectswat1", duration = 4, Tag = 0},
  34.                 {Name = "_insectswat2", duration = 3, Tag = 0},
  35.                 {Name = "_kneecheck", duration = 3, Tag = 0},
  36.                 {Name = "_laces", duration = 6, Tag = 0},
  37.                 {Name = "_legbob", duration = 2, Tag = 0},
  38.                 {Name = "_massageneck", duration = 3, Tag = 0},
  39.                 {Name = "_shouldershrug", duration = 4, Tag = 0},
  40.                 {Name = "_yawn", duration = 4, Tag = 0},
  41.                 
  42.                 },
  43.  
  44.         Animation     = "",
  45.         
  46. }    
  47.  
  48. function IdleManager:GetIdleAnimation( entity )
  49.     local model = entity.Properties.fileModel;
  50.     if (model) then    
  51.  
  52.         if (self.ModelTable[model]==nil) then 
  53.             local idleCounter = 0;
  54.             self.ModelTable[model]={};
  55.             local formatted_name = format("idle%02d",idleCounter);
  56.             while (entity:GetAnimationLength(formatted_name)~=0) do
  57.                 self.ModelTable[model][idleCounter+1] = {Name = formatted_name, Tag=0 };
  58.                 idleCounter = idleCounter + 1;
  59.                 formatted_name = format("idle%02d",idleCounter);
  60.             end
  61.             self.TagTable[model] = 1;
  62.             self.CountTable[model] = 0;
  63.         end        
  64.  
  65.         return self:GetIdle(model)
  66.     end
  67. end
  68.                 
  69.     
  70. function IdleManager:GetIdle( model_name )
  71.  
  72.     local table = self.ModelTable[model_name];
  73.     local count = getn(table);
  74.     
  75.     if( count < 1 ) then 
  76.         System:Warning( "[AI] No idle ainmation for "..model_name.." add animation or change the job ");
  77.         return nil; 
  78.     end
  79.     
  80.     local XRandom = random(1,count);
  81.     local XVal = 0;
  82.  
  83.     self.CountTable[model_name] =    self.CountTable[model_name] + 1; 
  84.  
  85.     if (self.CountTable[model_name] > count ) then
  86.         self.TagTable[model_name] = self.TagTable[model_name] + 1;
  87.         self.CountTable[model_name]=1;
  88.     end
  89.  
  90.     local TableTag = self.TagTable[model_name];
  91.  
  92.  
  93.     if (random(1,2) == 1) then
  94.         while (table[XRandom].Tag == TableTag) do
  95.             XRandom = XRandom + 1;
  96.             if (XRandom > count) then
  97.                 XRandom = 1;
  98.             end
  99.         end                
  100.     else
  101.         while (table[XRandom].Tag == TableTag) do
  102.             XRandom = XRandom - 1;
  103.             if (XRandom < 1) then
  104.                 XRandom = count;
  105.             end
  106.         end                
  107.     end
  108.  
  109.     table[XRandom].Tag = TableTag;
  110.     return table[XRandom];
  111. end                
  112.     
  113.     
  114.